# A minimalist example of using MetaDrive with the built-in PPO expert policy
from metadrive import MetaDriveEnv
from metadrive.examples import expert

config = {"start_seed": 1000,
          "num_scenarios": 1,
          "traffic_density": 0.1,
          }

env = MetaDriveEnv(config=config)

print("Starting the environment...")

ep_reward = 0.0
obs, info = env.reset()

print(f'obs shape is {obs.shape[0]}, obs type is {type(obs)}')
# print(f"obs is {obs}")

print("obs size is :", env.observation_space.shape[0])
print("act size is :", env.action_space.shape[0])

for i in range(1000):
    obs, reward, terminated, truncated, info = env.step(expert(env.agent))
    ep_reward += reward
    env.render(mode="top_down", screen_record=True, screen_size=(500, 500))
    if terminated or truncated:
        print(f"Arriving Destination: {info['arrive_dest']}.")
        print(f"Episode reward: {ep_reward}.")
        break

print(f"The last returned information: {info}.")
env.top_down_renderer.generate_gif()
env.close()
print("MetaDrive successfully run!")

